<?php
require 'includes/config.php';
require 'includes/sanitize.php';
require 'includes/makeRequest.php';

$data = sanitize($_POST);
$msg = "";
if ($signup && isset($data['submit'])) {
	if($_POST['pw1'] == $data['pw2']){
		$request = new makeRequest($backend.'api.php', 'POST', 'method=user&username='.$data['username'].
		'&password='.$_POST['pw1'].'&mail='.$data['mail'].'&firstname='.$data['firstname'].
		'&lastname='.$_POST['lastname'].'&age='.$data['age'].'&location='.$data['location']);
		$tmp = $request->makeRequest();
		$rbody = $tmp[0];
		$http_code = $tmp[1];
		// Check for errors
		if($http_code == 200){
			$msg = "User created, to login click <a href='login.php'>here</a>";
		}else{
			$msg = "User name taken";
		}
	}else{
		$msg = "Passwords doens't match";
	}
}
require 'includes/header.php';
require 'includes/topmenu.php';
echo '<div id="kaka">';
require 'includes/sidemenu.php'
?>

<div id="content">
<div id="info"><?php 
if($msg != ""){
	echo $msg;
}
?>
<table>
	<form method="post" action="<?php echo $PHP_SELF; ?>">
	
	
	<tr>
		<td>Username:<br />
		</td>
		<td><input type="text" name="username"
			value="<?php echo $data['username']; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td>Password:<br />
		</td>
		<td><input type="password" name="pw1" /><br />
		</td>
	</tr>
	<tr>
		<td>Repeat password: <br />
		</td>
		<td><input type="password" name="pw2" /><br />
		</td>
	</tr>
	<tr>
		<td>Mail: <br />
		</td>
		<td><input type="text" name="mail"
			value="<?php echo $data['mail']; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td>First name: <br />
		</td>
		<td><input type="text" name="firstname"
			value="<?php echo $data['firstname']; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td>Last name: <br />
		</td>
		<td><input type="text" name="lastname"
			value="<?php echo $data['lastname']; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td>Location: <br />
		</td>
		<td><input type="text" name="location"
			value="<?php echo $data['location']; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td>Age: <br />
		</td>
		<td><input type="text" name="age" value="<?php echo $data['age']; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td><input type="submit" Value="Submit" name="submit" />

		</form>
		</td>
		<td></td>
	</tr>
</table>
</div>
<?php
require 'includes/footer.php';
?>

</body>
</html>